<!--
 * @Author: Dorange.Wang
 * @Date: 2021-05-12 18:21:04
 * @LastEditors: wangming
 * @LastEditTime: 2021-12-09 10:22:42
 * @Description: file content
-->
<template>
  <el-dialog :visible="showVisible" center :show-close="false" width="800px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>{{ "历史版本" }}</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>

    <div class="pl30 pr30">
      <el-table
        ref="table"
        :data="tableData"
        style="width: 100%"
        current-row-key="id"
        stripe
        border
        v-loading="loading"
      >
        <el-table-column prop="version" label="版本编号">
          <template slot-scope="scope">
            {{ scope.row.version | version
            }}{{ scope.row.activated ? "【已激活】" : "" }}
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="版本描述" />
        <el-table-column prop="createDate" label="创建时间">
          <template slot-scope="scope">
            {{ scope.row.createDate | moment }}
          </template>
        </el-table-column>
        <el-table-column prop="actions" label="操作">
          <template slot-scope="scope">
            <span v-if="!scope.row.activated" class="table-actionItem"
              ><el-button type="text" @click="handleActivate(scope.row)"
                >激活</el-button
              ></span
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- <div class="tr mt24">
        <x-pagination
          :total="result.errsize"
          :pageSize.sync="pageData.pageSize"
          :pageNo.sync="pageData.pageNo"
          @search="loadData"
        />
      </div> -->
    </div>
  </el-dialog>
</template>

<script>
import { getHmmodelpublishList,putHmmodelpublishActivate } from '@/apis/paas/HmModelPublishController.js'
export default {
  data() {
    return {
      loading: false,
      showVisible: false,
      pageData: {
        pageSize: 10,
        pageNo: 1,
      },
      tableData: [],
      callback: null,
    };
  },

  methods: {
    async open(data = {}, callback) {
      this.tableData = [];
      this.pageData = {
        pageSize: 10,
        pageNo: 1,
      };
      this.callback = callback;
      await this.loadVerList(data.id);
      this.showVisible = true;
    },

    close() {
      this.showVisible = false;
    },

    async loadVerList(id) {
      if (!id) {
        return;
      }
      this.loading = true;
      try {
        this.tableData = await getHmmodelpublishList({
          modelId: id,
        });
      } catch (error) {}
      this.loading = false;
      if (!this.tableData.length) {
        this.$message.info("暂无激活版本，请点击模型编码添加字段。");
        return Promise.reject();
      }
    },

    handleActivate(record) {
      putHmmodelpublishActivate({
        id: record.id,
      }).then(() => {
        this.$message.success("操作成功");
        this.callback && this.callback();
        this.close();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
